package com.itzz.spring_zhoneHeng.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itzz.spring_zhoneHeng.pojo.Module;
import com.itzz.spring_zhoneHeng.pojo.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserDao extends BaseMapper<User> {
    List<User> queryAll(User user);

    //获取用户的权限  把用户的权限信息放进Authority中
    List<Module> getRole(String username);

    //删除对应的用户和角色表   根据uid删除u_r表
    @Delete("delete from u_r where uid=#{uid}")
    void delU_R(Integer uid);

    //删除对应的用户和会员表   根据uid删除u_mb表
//    @Delete("delete from u_mb where uid=#{uid}")
//    void delU_MB(Integer uid);

    //添加对应的用户和角色表
    void addU_R(@Param("uid") Integer uid,@Param("rids") Integer[] rids);

    //根据用户名查询用户的余额
    @Select("select money from `user` where username=#{username}")
    Double queryMoney(String username);

    //修改用户的余额
    @Update("update `user` set money=#{money}-20 where username=#{username}")
    void updateMoney(String username,Double money);

    //根据用户的姓名查询用户个人信息
    @Select("select * from `user` where username=#{username}")
    User queryUser(String username);

    //用户充值
    @Update("update `user` set money=#{money}+money where username=#{username}")
    void AddMoney(String username,Double money);

    //根据用户id查询u_r表 获取rid   根据rid  查询role表 获取roleName
    @Select("select r.`name` from u_r u,role r where u.rid=r.id and u.uid=#{uid}")
    String queryRoleName(Integer uid);

    //根据userid查询u_ms表  中的messid
    @Select("select messid from u_ms where userid=#{uid}")
    List<Integer> queryMessId(Integer uid);


    //根据用户id查询关联表u_bs中的bsid
    @Select("select bsid from u_bs where uid=#{uid}")
    List<Integer> queryByBsid(Integer uid);








}
